﻿// Decompiled with JetBrains decompiler
// Type: System.Web.Razor.RazorTemplateEngine
// Assembly: System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: 682513D6-F37E-48AC-9909-F3EE103CFF14
// Assembly location: D:\Project\Idea\无人机外网\uav\客户端工程\排查工具\bin\Release\System.Web.Razor.dll

using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Web.Razor.Generator;
using System.Web.Razor.Parser;
using System.Web.Razor.Text;

namespace System.Web.Razor
{
  /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Represents an entry-point to the Razor Template Engine.</summary>
  public class RazorTemplateEngine
  {
    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Indicates the default class name of the template.</summary>
    public static readonly string DefaultClassName = "Template";
    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Indicates the default namespace for the template.</summary>
    public static readonly string DefaultNamespace = string.Empty;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Initializes a new instance of the <see cref="T:System.Web.Razor.RazorTemplateEngine" /> class.</summary>
    /// <param name="host">The host.</param>
    public RazorTemplateEngine(RazorEngineHost host) => this.Host = host != null ? host : throw new ArgumentNullException(nameof (host));

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets or sets the <see cref="T:System.Web.Razor.RazorEngineHost" /> which defines the environment in which the generated template code will live.</summary>
    /// <returns>The <see cref="T:System.Web.Razor.RazorEngineHost" /> which defines the environment in which the generated template code will live.</returns>
    public RazorEngineHost Host { get; private set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer and returns its result.</summary>
    /// <returns>The resulting parse tree.</returns>
    /// <param name="input">The input text to parse.</param>
    public ParserResults ParseTemplate(ITextBuffer input) => this.ParseTemplate(input, new CancellationToken?());

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer and returns its result.</summary>
    /// <returns>The resulting parse tree.</returns>
    /// <param name="input">The input text to parse.</param>
    /// <param name="cancelToken">A token used to cancel the parser.</param>
    public ParserResults ParseTemplate(
      ITextBuffer input,
      CancellationToken? cancelToken)
    {
      return this.ParseTemplateCore(input.ToDocument(), cancelToken);
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer and returns its result.</summary>
    /// <returns>The resulting parse tree.</returns>
    /// <param name="input">The input text to parse.</param>
    public ParserResults ParseTemplate(TextReader input) => this.ParseTemplate(input, new CancellationToken?());

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer and returns its result.</summary>
    /// <returns>The resulting parse tree.</returns>
    /// <param name="input">The input text to parse.</param>
    /// <param name="cancelToken">A token used to cancel the parser.</param>
    public ParserResults ParseTemplate(
      TextReader input,
      CancellationToken? cancelToken)
    {
      return this.ParseTemplateCore((ITextDocument) new SeekableTextReader(input), cancelToken);
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template core.</summary>
    /// <returns>The resulting parse tree.</returns>
    /// <param name="input">The input text to parse.</param>
    /// <param name="cancelToken">A token used to cancel the parser.</param>
    protected internal virtual ParserResults ParseTemplateCore(
      ITextDocument input,
      CancellationToken? cancelToken)
    {
      return this.CreateParser().Parse(input);
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer, generates code for it, and returns the constructed CodeDOM tree.</summary>
    /// <returns>The resulting parse tree AND generated Code DOM tree.</returns>
    /// <param name="input">The input text to parse.</param>
    public GeneratorResults GenerateCode(ITextBuffer input) => this.GenerateCode(input, (string) null, (string) null, (string) null, new CancellationToken?());

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer, generates code for it, and returns the constructed CodeDOM tree.</summary>
    /// <returns>The resulting parse tree AND generated Code DOM tree.</returns>
    /// <param name="input">The input text to parse.</param>
    /// <param name="cancelToken">A token used to cancel the parser.</param>
    public GeneratorResults GenerateCode(
      ITextBuffer input,
      CancellationToken? cancelToken)
    {
      return this.GenerateCode(input, (string) null, (string) null, (string) null, cancelToken);
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer, generates code for it, and returns the constructed CodeDOM tree.</summary>
    /// <returns>The resulting parse tree AND generated Code DOM tree.</returns>
    /// <param name="input">The input text to parse.</param>
    /// <param name="className">The name of the generated class, overriding whatever is specified in the host.</param>
    /// <param name="rootNamespace">The namespace in which the generated class will reside.</param>
    /// <param name="sourceFileName">The file name to use in line pragmas.</param>
    public GeneratorResults GenerateCode(
      ITextBuffer input,
      string className,
      string rootNamespace,
      string sourceFileName)
    {
      return this.GenerateCode(input, className, rootNamespace, sourceFileName, new CancellationToken?());
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer, generates code for it, and returns the constructed CodeDOM tree.</summary>
    /// <returns>The resulting parse tree AND generated Code DOM tree.</returns>
    /// <param name="input">The input text to parse.</param>
    /// <param name="className">The name of the generated class, overriding whatever is specified in the host.</param>
    /// <param name="rootNamespace">The namespace in which the generated class will reside.</param>
    /// <param name="sourceFileName">The file name to use in line pragmas.</param>
    /// <param name="cancelToken">A token used to cancel the parser.</param>
    public GeneratorResults GenerateCode(
      ITextBuffer input,
      string className,
      string rootNamespace,
      string sourceFileName,
      CancellationToken? cancelToken)
    {
      return this.GenerateCodeCore(input.ToDocument(), className, rootNamespace, sourceFileName, cancelToken);
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer, generates code for it, and returns the constructed CodeDOM tree.</summary>
    /// <returns>The resulting parse tree AND generated Code DOM tree.</returns>
    /// <param name="input">The input text to parse.</param>
    public GeneratorResults GenerateCode(TextReader input) => this.GenerateCode(input, (string) null, (string) null, (string) null, new CancellationToken?());

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer, generates code for it, and returns the constructed CodeDOM tree.</summary>
    /// <returns>The resulting parse tree AND generated Code DOM tree.</returns>
    /// <param name="input">The input text to parse.</param>
    /// <param name="cancelToken">A token used to cancel the parser.</param>
    public GeneratorResults GenerateCode(
      TextReader input,
      CancellationToken? cancelToken)
    {
      return this.GenerateCode(input, (string) null, (string) null, (string) null, cancelToken);
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer, generates code for it, and returns the constructed CodeDOM tree.</summary>
    /// <returns>The resulting parse tree AND generated Code DOM tree.</returns>
    /// <param name="input">The input text to parse.</param>
    /// <param name="className">The name of the generated class, overriding whatever is specified in the host.</param>
    /// <param name="rootNamespace">The namespace in which the generated class will reside.</param>
    /// <param name="sourceFileName">The file name to use in line pragmas.</param>
    public GeneratorResults GenerateCode(
      TextReader input,
      string className,
      string rootNamespace,
      string sourceFileName)
    {
      return this.GenerateCode(input, className, rootNamespace, sourceFileName, new CancellationToken?());
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Parses the template specified by the TextBuffer, generates code for it, and returns the constructed CodeDOM tree.</summary>
    /// <returns>The resulting parse tree AND generated Code DOM tree.</returns>
    /// <param name="input">The input text to parse.</param>
    /// <param name="className">The name of the generated class, overriding whatever is specified in the host.</param>
    /// <param name="rootNamespace">The namespace in which the generated class will reside.</param>
    /// <param name="sourceFileName">The file name to use in line pragmas.</param>
    /// <param name="cancelToken">A token used to cancel the parser.</param>
    public GeneratorResults GenerateCode(
      TextReader input,
      string className,
      string rootNamespace,
      string sourceFileName,
      CancellationToken? cancelToken)
    {
      return this.GenerateCodeCore((ITextDocument) new SeekableTextReader(input), className, rootNamespace, sourceFileName, cancelToken);
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Generates a code core.</summary>
    /// <returns>The results of the generated core.</returns>
    /// <param name="input">The input text to parse.</param>
    /// <param name="className">The name of the generated class, overriding whatever is specified in the host.</param>
    /// <param name="rootNamespace">The namespace in which the generated class will reside.</param>
    /// <param name="sourceFileName">The file name to use in line pragmas.</param>
    /// <param name="cancelToken">A token used to cancel the parser.</param>
    protected internal virtual GeneratorResults GenerateCodeCore(
      ITextDocument input,
      string className,
      string rootNamespace,
      string sourceFileName,
      CancellationToken? cancelToken)
    {
      className = (className ?? this.Host.DefaultClassName) ?? RazorTemplateEngine.DefaultClassName;
      rootNamespace = (rootNamespace ?? this.Host.DefaultNamespace) ?? RazorTemplateEngine.DefaultNamespace;
      ParserResults parserResults = this.CreateParser().Parse(input);
      RazorCodeGenerator codeGenerator = this.CreateCodeGenerator(className, rootNamespace, sourceFileName);
      codeGenerator.DesignTimeMode = this.Host.DesignTimeMode;
      codeGenerator.Visit(parserResults);
      this.Host.PostProcessGeneratedCode(codeGenerator.Context);
      IDictionary<int, GeneratedCodeMapping> designTimeLineMappings = (IDictionary<int, GeneratedCodeMapping>) null;
      if (this.Host.DesignTimeMode)
        designTimeLineMappings = codeGenerator.Context.CodeMappings;
      return new GeneratorResults(parserResults, codeGenerator.Context.CompileUnit, designTimeLineMappings);
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Creates a code generator.</summary>
    /// <returns>The created <see cref="T:System.Web.Razor.Generator.RazorCodeGenerator" />.</returns>
    /// <param name="className">The name of the generated class.</param>
    /// <param name="rootNamespace">The namespace in which the generated class will reside.</param>
    /// <param name="sourceFileName">The file name to use in line pragmas.</param>
    protected internal virtual RazorCodeGenerator CreateCodeGenerator(
      string className,
      string rootNamespace,
      string sourceFileName)
    {
      return this.Host.DecorateCodeGenerator(this.Host.CodeLanguage.CreateCodeGenerator(className, rootNamespace, sourceFileName, this.Host));
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Creates a <see cref="T:System.Web.Razor.Parser.RazorParser" />.</summary>
    /// <returns>The created <see cref="T:System.Web.Razor.Parser.RazorParser" />.</returns>
    protected internal virtual RazorParser CreateParser()
    {
      ParserBase codeParser = this.Host.CodeLanguage.CreateCodeParser();
      ParserBase markupParser = this.Host.CreateMarkupParser();
      return new RazorParser(this.Host.DecorateCodeParser(codeParser), this.Host.DecorateMarkupParser(markupParser))
      {
        DesignTimeMode = this.Host.DesignTimeMode
      };
    }
  }
}
